// 对于数据请求的封装

import axios from 'axios'
import { Toast } from 'vant'

const http = axios.create({
  baseURL: 'https://m.maizuo.com', // 路径的基础地址
  timeout: 10000,
  headers: {
    'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"1629961839595441381015553","bc":"440300"}'
  }
})

// 在发请求之前拦截 --- showLoading
http.interceptors.request.use(function (config) {
  Toast.loading({
    message: '加载中...',
    forbidClick: true,
    duration: 0
  })
  // console.log(config)
  return config
}, function (error) {
  return Promise.reject(error)
})

// 在成功后拦截 --- hideLoading
http.interceptors.response.use(function (response) {
  Toast.clear()
  return {
    ...response,
    msg: '可以在这里给请求到的数据加点东西'
  }
}, function (error) {
  Toast.clear()
  return Promise.reject(error)
})

export default http
